//
// Created by hjie on 23-6-1.
//

#include <cstring>
#include <unistd.h>
#include <atomic>
#include "stun_client_option.h"
#include "./../stun_message.h"
#include "./../../loop_event/loop_event_define.h"
#include "media_process_client.h"

class StunClient
{
public:
    StunClient(LoopEvent * loop);
    void InitOption(StunClientOption & option);
    void OnMessage(UdpBufferPacket * packet);
    void SendMessage();
    void SendBindRequest(const std::string & transaction_id);
    void SendAllocateRequest();
    void StartClient();
private:
    void ProcessStunMessageByStatus(StunMessage * message, UdpBufferPacket * packet);
    void ProcessStunMessage(StunMessage * message, UdpBufferPacket * packet);
private:
    void ProcessInitStatus(StunMessage      * message, UdpBufferPacket * packet);
    void ProcessAllocateStatus(StunMessage  * message, UdpBufferPacket * packet);
    void ProcessAllocateWaiting(StunMessage * message, UdpBufferPacket * packet);
    void ProcessHeartStatus(StunMessage     * message, UdpBufferPacket * packet);
    void ProcessAllocateError(StunMessage   * message, UdpBufferPacket * packet);
private:
    std::atomic<bool> m_client_status;
    StunClientOption m_option;
private:
    UdpClient * m_udp_client;
    LoopEvent * m_loop_event;
private:
    std::string m_local_public_ip;
    uint16_t m_local_public_port;
private:
    std::shared_ptr<MediaProcessClient> m_media_client;
};


